package com.victor.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.victor.entity.Activity;
import com.victor.entity.ActivityJD;
import com.victor.service.ActivityService;
import com.victor.utils.Msg;

/**
 * 旅游活动管理
 * 
 * @author zhangbin
 *
 */
@RestController
@RequestMapping("/activity")
public class ActivityController {

	@Autowired
	private ActivityService service;

	// 获取筛选类型-->JingquController(获取所有景区类别)

	// 获取列表 （传type和jqclassid）
	@RequestMapping("/getlist")
	public Msg getActivityList(String type, String jqclassid, @RequestParam(value = "pn", defaultValue = "1") int pn) {
		PageMethod.startPage(pn, 10);
		List<Activity> activities = service.getlist(type, jqclassid);
		PageInfo page = new PageInfo(activities, 4);
		return Msg.success().add("activities", page);
	}

	// 通过id查询详情
	@RequestMapping("/getActivityXQ")
	public Msg getActivityXQ(String activityid) {

		Activity activity = service.getActivityXQ(activityid);
		if (activity != null) {
			return Msg.success().add("activity", activity);
		}
		return Msg.fail();
	}

	// 批量删除活动
	@RequestMapping("deleteActivityByids")
	public Msg deleteActivityByids(int[] acids) {
		boolean delResult = service.deleteActivityByids(acids);
		return Msg.judge(delResult);
	}

	// 修改活动
	@RequestMapping("updateActivityPrice")
	public Msg updateActivityPrice(@RequestBody Activity activity) {
		// 修改活动景区信息
		int i = service.updateActivi(activity);
		List<ActivityJD> activityJDs = activity.getActivityjd();

		if (activityJDs != null && activityJDs.size() > 0) {
			// 修改活动景点信息
			service.updateactivityJD(activityJDs);
		}
		if (i > 0) {
			return Msg.success();
		}
		return Msg.fail();
	}

	// 团购
}
